<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="Product"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="Product" type="Domain.Product" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="Product">
			<result property="productId" column="productId" dbType="Int"/>
			<result property="productName" column="productName" dbType="NVarChar"/>
			<result property="productModelNO" column="productModelNO" dbType="NVarChar"/>
			<result property="productType" column="productType" dbType="Int"/>
			<result property="markedPrice" column="markedPrice" dbType="Money"/>
			<result property="memberPrice" column="memberPrice" dbType="Money"/>
			<result property="minOrderNumber" column="minOrderNumber" dbType="Int"/>
			<result property="productStockNumber" column="productStockNumber" dbType="Int"/>
			<result property="productIntro" column="productIntro" dbType="NText"/>
			<result property="productOtherInfo" column="productOtherInfo" dbType="NText"/>
			<result property="productHits" column="productHits" dbType="Int"/>
			<result property="productImages" column="productImages" dbType="NVarChar"/>
			<result property="addTime" column="addTime" dbType="SmallDateTime"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[product]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="Product">
			SELECT * 
			FROM [dbo].[product]
		</select>
		
		<select id="GetModel" parameterClass="Product" resultClass="Product" extends="FindAll">
			WHERE
				([product].[productId] = #productId,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="Product">
      INSERT INTO [dbo].[product] (

      [productName] ,
      [productModelNO] ,
      [productType] ,
      [markedPrice] ,
      [memberPrice] ,
      [minOrderNumber] ,
      [productStockNumber] ,
      [productIntro] ,
      [productOtherInfo] ,
      [productHits] ,
      [productImages] ,
      [addTime],
      [productShowOrder],
      [productIndexOrder],
      [productListOrder]
      ) VALUES (

      #productName,dbType=NVarChar# ,
      #productModelNO,dbType=NVarChar# ,
      #productType,dbType=Int# ,
      #markedPrice,dbType=Money# ,
      #memberPrice,dbType=Money# ,
      #minOrderNumber,dbType=Int# ,
      #productStockNumber,dbType=Int# ,
      #productIntro,dbType=NText# ,
      #productOtherInfo,dbType=NText# ,
      #productHits,dbType=Int# ,
      #productImages,dbType=NVarChar# ,
      #addTime,dbType=SmallDateTime#,
      #productShowOrder,dbType=Int#,
      #productIndexOrder,dbType=Int#,
      #productListOrder,dbType=Int#
      )
    </insert>

		<update id="Update" parameterClass="Product">
      UPDATE [dbo].[product] SET
      [productName] = #productName,dbType=NVarChar#
      , [productModelNO] = #productModelNO,dbType=NVarChar#
      , [productType] = #productType,dbType=Int#
      , [markedPrice] = #markedPrice,dbType=Money#
      , [memberPrice] = #memberPrice,dbType=Money#
      , [minOrderNumber] = #minOrderNumber,dbType=Int#
      , [productStockNumber] = #productStockNumber,dbType=Int#
      , [productIntro] = #productIntro,dbType=NText#
      , [productOtherInfo] = #productOtherInfo,dbType=NText#
      , [productHits] = #productHits,dbType=Int#
      , [productImages] = #productImages,dbType=NVarChar#
      , [addTime] = #addTime,dbType=SmallDateTime#
      , [productShowOrder]= #productShowOrder,dbType=Int#
      , [productIndexOrder]= #productIndexOrder,dbType=Int#
      , [productListOrder]= #productListOrder,dbType=Int#
      WHERE
      ([productId] = #productId,dbType=Int#)
    </update>

		<delete id="Delete" parameterClass="Product">
			DELETE FROM [dbo].[product]
			WHERE
				([productId] = #productId,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="Product">
			SELECT $columnNames$ FROM [dbo].[product] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="Product">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [productId] from [dbo].[product]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[product] ,@indextable t
      <![CDATA[
			where t.nid= [product].productId and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
